#ifndef MYWIDGET_H
#define MYWIDGET_H

#include "tcpclient.h"
#include <QWidget>
#include <QDialog>
#include <QMessageBox>
#include <QCloseEvent>
#include <QDebug>
#include <QThread>
#include <QFile>
#include <QFileDialog>
#include <QTimer>
#include <QString>
#include <QProgressBar>
#include <QProgressDialog>

QT_BEGIN_NAMESPACE
namespace Ui {
class MyWidget;
}
QT_END_NAMESPACE

class MyWidget : public QWidget
{
    Q_OBJECT

public:
    explicit MyWidget(QWidget *parent = nullptr, QString ip = "", QString name = "");
    ~MyWidget();
    void closeEvent(QCloseEvent *event) override;

public slots:
    void tcpConnectStateChanged(QAbstractSocket::SocketState state);
    void tcpErrorOccured(QAbstractSocket::SocketError error);
    void saveReceieveFiles();
    void displayDiagnosisResult(QString result);
    void acceptServerInformation(QString result);
    void updateDataCollectTimeWaste();
    void setProgressBarValue(float speed, float receiveSize, float totalSize);
    void cancelFileTransimit();

signals:
    void connectToServer(QString ip, quint16 port = TCP_SERVER_PORT);
    void disconnectFromServer();
    void dataCollectStart(const qint64 cmd, QString path);
    void dataCollectStop(const qint64 cmd);
    void faultDiagnoseSignal(const qint64 cmd);
    void cancelTransimition(const qint64 cmd);
    void textLabel(QString text);

private:
    Ui::MyWidget *ui;
    TcpClient *var_tcpClient;
    QThread var_tcpClientThread;
    QTimer var_dataCollectTime;
    bool if_dataCollectSuccess = false;
    bool if_messageBoxShown = false;
    QProgressDialog *var_progress;
    QTimer *var_timer; // 检测是否断连
    QString var_ip;
    QString var_name;
    quint64 var_timeWasteNum;
};

#endif // MYWIDGET_H
